package com.redis.common.component.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @Author C_Y_J
 * @create 2022/1/20 9:53
 **/
@Slf4j
public class AuthenticationLogoutEventHandler implements AuthenticationLogoutHandler {

    /**
     * 处理退出成功方法
     * <p>
     * 获取到登录的authentication 对象
     *
     * @param authentication 登录对象
     * @param request        请求
     * @param response       返回
     */
    @Async
    @Override
    public void handle(Authentication authentication, HttpServletRequest request, HttpServletResponse response) {
        String username = authentication.getName();
        // 退出的token
        String token = request.getHeader(HttpHeaders.AUTHORIZATION);
        log.info("用户：{} 退出成功, token:{}  已注销", username, token);
    }
}